package net.minecraft.src;

import java.util.ArrayList;
import java.util.Random;

public class LF_BlockTVOn extends LF_BlockFurnitureBase
{
	public LF_BlockTVOn(int i, int j, Class class1, Material mat)
	{
		super(i, j, class1, mat);
		setLightValue(100);
	}

	public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer)
	{
		LF_TileEntityTV tile = (LF_TileEntityTV)(world.getBlockTileEntity(i, j, k));
		tile.channel++;

		if(tile.channel > 8)
			tile.channel = 1;

		Packet230ModLoader packet = new Packet230ModLoader();
		packet.dataInt = new int[6];
		packet.dataInt[0] = 0;
		packet.dataInt[1] = tile.worldObj.getWorldInfo().getDimension();
		packet.dataInt[2] = tile.xCoord;
		packet.dataInt[3] = tile.yCoord;
		packet.dataInt[4] = tile.zCoord;
		packet.dataInt[5] = tile.channel;
		ModLoaderMp.sendPacketToAll(ModLoaderMp.getModInstance(mod_LF_GenericFurnitureMain.class), packet);

		return true;
	}

	public void onNeighborBlockChange(World world, int i, int j, int k, int l)
	{
		world.scheduleBlockUpdate(i, j, k, blockID, tickRate());
	}

	public void updateTick(World world, int i, int j, int k, Random random)
	{
		Packet230ModLoader packet = new Packet230ModLoader();
		LF_TileEntityTV tile = ((LF_TileEntityTV)world.getBlockTileEntity(i,j,k));

		if(tile == null)
			return;

		int m = world.getBlockMetadata(i, j, k);
		if(!world.isBlockIndirectlyGettingPowered(i, j, k))
		{
			if(world.getBlockId(i,j,k) == this.blockID)
			{
				world.setBlockAndMetadata(i, j, k, mod_LF_GenericFurnitureMain.blockTVOff.blockID, m);
				world.scheduleBlockUpdate(i, j, k, mod_LF_GenericFurnitureMain.blockTVOff.blockID, tickRate());

				packet.dataInt = new int[6];
				packet.dataInt[0] = 0;
				packet.dataInt[1] = tile.worldObj.getWorldInfo().getDimension();
				packet.dataInt[2] = tile.xCoord;
				packet.dataInt[3] = tile.yCoord;
				packet.dataInt[4] = tile.zCoord;
				packet.dataInt[5] = 0;
				ModLoaderMp.sendPacketToAll(ModLoaderMp.getModInstance(mod_LF_GenericFurnitureMain.class), packet);
			}
		}
		else
		{
			world.scheduleBlockUpdate(i, j, k, this.blockID, tickRate());

			packet.dataInt = new int[6];
			packet.dataInt[0] = 0;
			packet.dataInt[1] = tile.worldObj.getWorldInfo().getDimension();
			packet.dataInt[2] = tile.xCoord;
			packet.dataInt[3] = tile.yCoord;
			packet.dataInt[4] = tile.zCoord;
			packet.dataInt[5] = tile.channel;
			ModLoaderMp.sendPacketToAll(ModLoaderMp.getModInstance(mod_LF_GenericFurnitureMain.class), packet);
		}
	}

	public int tickRate()
	{
		return 5;
	}

	public int idDropped(int i, Random random, int j)
	{
		return mod_LF_GenericFurnitureMain.itemTV.shiftedIndex;
	}
}